home *** CD-ROM | disk | FTP | other *** search
Wrap
var FlashVD = { options : null, cache: null, // video, audio, adult urls internal persistent storage // categorized urls // should be taken from http://flashvideodownloader.org/fvd-suite/sites/video.php video : [], audio : [], adult : [], inpage_sites : [ 'santabanta','google','hulu','collegehumor','metacafe','dailymotion','dada','redtube','youtube' ], read_reg_string : function (a, b) { //var c = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); try { return FlashVD.options.getComplexValue(a, Components.interfaces.nsISupportsString).data; } catch(e) { return b; } }, write_reg_string : function (a, b) { //var c = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); try { var d = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); d.data = b; FlashVD.options.setComplexValue(a, Components.interfaces.nsISupportsString, d); return true; } catch(e) { return false; } }, showLic : function() { window.openDialog("chrome://flashvideodownloader/content/lic.xul", "lic", "width=" + (window.screen.availWidth/2 - 133) + ",height=" + (window.screen.availHeight/2) + ",chrome,modal,centerscreen"); }, init : function() { try { if (!FlashVD.options) FlashVD.options = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("FlashVD.options."); if (!FlashVD.cache) FlashVD.cache = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("FlashVD.cache."); if (FlashVD.video.length == 0) FlashVD.loadUrlsFromCache("video", FlashVD.video); if (FlashVD.audio.length == 0) FlashVD.loadUrlsFromCache("audio", FlashVD.audio); if (FlashVD.adult.length == 0) FlashVD.loadUrlsFromCache("adult", FlashVD.adult); //FlashVD.updateCache(); } catch (e) { //alert("init\n" + e); } try { var is_it_first = FlashVD.options.getBoolPref('flash_fr'); } catch(e) { FlashVD.options.setBoolPref('flash_fr', true); //FlashVD.showLic(); } }, updateCacheByTimer : function() { try { updated = FlashVD; var curDateTime = new Date(); var curDay = 13;//curDateTime.getDate(); var curHour = curDateTime.getHours(); //var curState = curDay*24 + curHour; // hourly var curState = Math.floor(curDay/2); // daily // simple update - only if hour/day changed or more var lastState = curState - 1; try { lastState = FlashVD.cache.getIntPref("state"); } catch(e) {} if (curState != lastState) { //alert("curState=" + curState + "\nlastState=" + lastState); FlashVD.updateCache(); } FlashVD.cache.setIntPref("state", curState); } catch (e) { //alert("updateCacheByTimer\n" + e); } }, updateCache : function() { try { FlashVD.requestUrls("video", FlashVD.video); //FlashVD.requestUrls("audio", FlashVD.audio); FlashVD.requestUrls("adult", FlashVD.adult); } catch (e) { //alert("updateCache\n" + e); } }, processTextUrls : function (category, urls, text_urls) { try { var arr = text_urls.split("\n"); if (arr.length == 0) return; //alert("processTextUrls " + category + " - arr.length = " + arr.length + "\n" + arr.toString()); // reset urls urls.length = 0; for(var i = 0; i < arr.length; i++) { var url = arr[i]; if (url.length < 8)// "http://".length) continue; if (url.indexOf("http://www.") == 0) url = url.substring(11); else if (url.indexOf("http://") == 0) url = url.substring(7); urls.push(url); } //alert("processTextUrls " + category + " - urls.length = " + urls.length + "\n" + urls.toString()); } catch(e) { //alert("processTextUrls() failed.\n" + e); } }, loadUrlsFromCache : function (category, urls) { try { // 1. Load text_urls from cache var text_urls = null; try{text_urls = FlashVD.cache.getCharPref(category); } catch(e) {} if (text_urls == null || text_urls == "") // cache is empty { // request urls from site - async cache update FlashVD.requestUrls(category, urls); return; } //alert("loadUrlsFromCache\n" + text_urls); // 2. Load data to urls FlashVD.processTextUrls(category, urls, text_urls); } catch (e) { //alert("loadUrlsFromCache\n" + e); } }, processResponse : function (category, urls, text_urls) { try { // 1. Save new text_urls to cache FlashVD.cache.setCharPref(category, text_urls); //alert("processResponse\n" + text_urls); // 2. Load data to urls FlashVD.processTextUrls(category, urls, text_urls); } catch (e) { //alert("processResponse\n" + e); } }, requestUrls : function (category, urls_array) { try { var req = new XMLHttpRequest(); req.open('GET', 'http://flashvideodownloader.org/fvd-suite/sites/' + category + '.php', true); req.onreadystatechange = function (aEvt) { if (req.readyState == 4) { if (req.status == 200) //alert(req.responseText); FlashVD.processResponse(category, urls_array, req.responseText); //else //alert("Error loading http://flashvideodownloader.org/fvd-suite/sites/video.php"); } }; req.send(null); } catch (e) { //alert("requestUrls\n" + e); } }, ila_load : function() { FlashVD.init(); FlashVD.updateCacheByTimer(); document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", FlashVD.init_cont_items, false); try { var hotk = FlashVD.options.getCharPref('hotkey'); var hotm = FlashVD.options.getCharPref('hot_mod'); } catch(e) { FlashVD.options.setCharPref('hotkey', 'L'); FlashVD.options.setCharPref('hot_mod', 'alt any control'); } try { var is_it_first = FlashVD.options.getBoolPref('flashvideodownloader'); } catch(e) { FlashVD.options.setBoolPref('flashvideodownloader', true); FlashVD.set_first_time_icons(); } }, set_first_time_icons : function() { try { var toolbox = document.getElementById("navigator-toolbox"); var toolboxDocument = toolbox.ownerDocument; var has_ila_tool_icon = false; for (var i = 0; i < toolbox.childNodes.length; ++i) { var toolbar = toolbox.childNodes[i]; if (toolbar.localName == "toolbar" && toolbar.getAttribute("customizable")=="true"){ if(toolbar.currentSet.indexOf("ila_tool_icon") > -1) hasDeliciousButton = true; } } if(!has_ila_tool_icon) { var toolbar = document.getElementById("nav-bar"); var newSet = ""; var child = toolbar.firstChild; while(child){ //Order of buttons is important if(!has_ila_tool_icon && child.id == "urlbar-container") { newSet += "ila_tool_icon,"; has_ila_tool_icon = true; } newSet += child.id+","; child = child.nextSibling; } newSet = newSet.substring(0, newSet.length-1); toolbar.currentSet = newSet; toolbar.setAttribute("currentset", newSet); toolboxDocument.persist(toolbar.id, "currentset"); try { BrowserToolboxCustomizeDone(true); }catch (e){} } } catch(e) { //alert("set_first_time_icons\n" + e); } }, ila_hotkey_f : function () { FlashVD.DownloadLink(); }, address_has : function (urls, params) { try { var addr = window.content.document.location.host; for(var i = 0; i < urls.length; i++) { var url = urls[i]; if (addr.indexOf(url) >= 0) { var addr = window.content.document.URL; if (addr.indexOf("http://www.") == 0) addr = addr.substring(11); else if (addr.indexOf("http://") == 0) addr = addr.substring(7); else if (addr.indexOf("www.") == 0) addr = addr.substring(4); //alert(addr + "\n" + url); if (addr.length - 1 <= url.length) params.isMainPage = true; return true; } } return false; } catch (e) { //alert("address_has\n" + e); return false; } }, set_icon : function () { try { FlashVD.init(); netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); try { var addr = window.content.document.location.host; } catch(e) { return; } var i_stat = false; //var parts = adr.match(/([^.]+)/ig); var tmp; //while(tmp=parts.pop()) //{ // if(FlashVD.sites.indexOf(tmp) != -1) // { // i_stat=true; // break; // } //} //if(tmp=='google'){if(parts.pop()!='video')i_stat=false;} //if(tmp=='myspace'){if(parts.pop()!='vids')i_stat=false;} //if(tmp=='streetfire'){if(parts.pop()!='videos')i_stat=false;} //if (FlashVD.video.length > 0) // alert("FlashVD.video:\n" + FlashVD.video.toString()); var params = {isMainPage:null}; var has_audio = FlashVD.address_has(FlashVD.audio, params); var has_video = FlashVD.address_has(FlashVD.video, params); var has_adult = FlashVD.address_has(FlashVD.adult, params); var icon=document.getElementById('ila_tool_icon'); i_stat = has_audio || has_video || has_adult; try { icon.setAttribute("adult_onpage", (has_adult ? "1" : "0")); icon.setAttribute("is_main_page", (params.isMainPage ? "1" : "0")); } catch (e) {} if(i_stat) { try { icon.setAttribute("video_onpage", "0"); icon.setAttribute("isset_in_db", "1"); icon.setAttribute("tooltiptext", "Download video or game"); } catch(e){} document.getElementById('flashvideodownloader-status').setAttribute("isset_in_db", "1"); document.getElementById('flashvideodownloader-tooltip-value').setAttribute("value", "Download video or game"); } else { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var embs = window.content.document.getElementsByTagName('embed'); var onpage_status = false; if(embs.length>0) { for(var i=0; i < embs.length; i++) { var emb = embs[i]; var partss = emb.src.match(/([^.]+)/ig); while(tmp = partss.pop()) { if(FlashVD.inpage_sites.indexOf(tmp)!=-1) { onpage_status=true; break; } } if(onpage_status)break; } } // Searching href if (!onpage_status) { var mediaPattern="mpg|mpeg|mp3|mp4|avi|rm|wmv|mov|flv|swf"; var mPatt=new RegExp("^.*\\.(?:"+mediaPattern+")$","i"); var dom=window.content.document;//window.content.document.documentElement; var Nodes = []; var xpr=dom.evaluate(".//a[@href]", dom, null, 5, // == Components.interfaces.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null); var node0=xpr.iterateNext(); while(node0!=null) { var url=node0.getAttribute("href"); if(mPatt.exec(url)!=null) { onpage_status=true; break; } node0=xpr.iterateNext(); } // Searching src if (!onpage_status) { xpr=dom.evaluate(".//embed[@src]", dom, null, 5, // == Components.interfaces.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null); node0=xpr.iterateNext(); while(node0!=null) { var url=node0.getAttribute("src"); if(mPatt.exec(url)!=null) { onpage_status=true; break; } node0=xpr.iterateNext(); } } } if(onpage_status==true) { icon.setAttribute("video_onpage", "1"); try { icon.setAttribute("isset_in_db", "1"); icon.setAttribute("tooltiptext", "Download video or game"); }catch(e){} document.getElementById('flashvideodownloader-status').setAttribute("isset_in_db", "1"); document.getElementById('flashvideodownloader-tooltip-value').setAttribute("value", "Download video or game"); } else { icon.setAttribute("video_onpage", "0"); try { icon.removeAttribute("isset_in_db"); //icon.setAttribute("tooltiptext", "Click to ask us add this service"); icon.setAttribute("tooltiptext", ""); }catch(e){} document.getElementById('flashvideodownloader-status').removeAttribute("isset_in_db"); //document.getElementById('flashvideodownloader-tooltip-value').setAttribute("value", "Click to ask us add this service"); document.getElementById('flashvideodownloader-tooltip-value').setAttribute("value", ""); } } } catch (e) { //alert("set_icon\n" + e); } }, init_cont_items : function () { var adr=window.content.document.location; try { if(adr.host=="www.flashvideodownloader.org" && adr.pathname=="/download.php") { if(gContextMenu.onLink) { document.getElementById('save_tmf_menu').hidden=false; document.getElementById('flashvideodownloader-context').hidden=true; } } else { document.getElementById('save_tmf_menu').hidden=true; document.getElementById('flashvideodownloader-context').hidden=false; } } catch(e){document.getElementById('save_tmf_menu').hidden=true;} }, save_to_my_folder : function(durl) { var folder; try { folder = FlashVD.options.getComplexValue ("favorite-folder", Components.interfaces.nsISupportsString); } catch (e) { alert('Please set your Favorite folder!'); return; } var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); var url; if(durl==''){url=gContextMenu.linkURL;}else{url=durl;} var uriObject = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI(url, null, null); var fileObject = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); try { fname = getDefaultFileName(null, uriObject, null, null); } catch(e) { fname = getDefaultFileName(null, null, uriObject, null); } if(fname=='get_video') { var time = new Date(); var month = time.getMonth()+1; fname=time.getFullYear()+'-'+month+'-'+time.getDate()+'_'+time.getHours()+'-'+time.getMinutes()+'-'+time.getSeconds()+'.mp4'; } if(fname=='videoplayback') { var time = new Date(); var month = time.getMonth()+1; fname=time.getFullYear()+'-'+month+'-'+time.getDate()+'_'+time.getHours()+'-'+time.getMinutes()+'-'+time.getSeconds()+'.flv'; } /* fileObject.initWithPath(folder); var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker); fp.init(window,'save as', Components.interfaces.nsIFilePicker.modeSave); fp.appendFilters(Components.interfaces.nsIFilePicker.filterAll); fp.defaultString = fname; fp.displayDirectory = fileObject; var res = fp.show(); if ((res == Components.interfaces.nsIFilePicker.returnOK) || (res == Components.interfaces.nsIFilePicker.returnReplace)){ fname = fp.file.leafName; folder = fp.file.path.substring(0, fp.file.path.length - fname.length); } else{return;} */ try { fileObject.initWithPath(folder); } catch(e) { alert('This folder not set.'); return; } fileObject.append(fname); try { var acObject = new AutoChosen(fileObject, uriObject); internalSave(url, null, fname, null, null, false, null, acObject, null, false); } catch(e) { saveURL(url, fileObject, null, false, false, null); } }, DownloadLink : function () { try { //FlashVD.updateCacheByTimer(); if(window.content.document.location=='about:blank') return true; if(FlashVD.read_reg_string('flashvideodownloaderlic', '0') == '0') { FlashVD.showLic(); //return; } if(FlashVD.read_reg_string('flashvideodownloaderlic', '0') == '0') { //FlashVD.showLic(); return; } var icon = document.getElementById('ila_tool_icon'); // adult check if (icon.getAttribute("adult_onpage")=='1') { // 1. Check "dont't ask me again" state var adult_notification = true; try { adult_notification = FlashVD.options.getBoolPref ("adult_notification"); } catch(e) {} // 2. Show warning if (adult_notification) { var params = {result:null}; window.openDialog("chrome://flashvideodownloader/content/adult_notification.xul",null, "chrome,modal,centerscreen", params); if (params.result == null) return; } } if (icon.getAttribute("isset_in_db")=='1') { if (icon.getAttribute("video_onpage")=='1') { FlashVD.download_from_any_page(); } else { // chek if cuurent address is main page if (icon.getAttribute("is_main_page")=='1') window.openDialog("chrome://flashvideodownloader/content/dialog.xul",null, "chrome,modal,centerscreen", null, "Warning! Downloading is impossible.", "You can't download this page", "Downloading from the Main page is disabled, please try another page."); else { // replaced by opening window in new tab //window.open('http://www.flashvideodownloader.org/download2.php?u='+content.document.location, "", "width=500,height=500,resizable=no"); // get the browser object var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); var mainWindow = wm.getMostRecentWindow("navigator:browser"); var browser = mainWindow.getBrowser(); // add new tab with our url var tab = browser.addTab('http://www.flashvideodownloader.org/download2.php?u='+content.document.location); // make the tab active browser.selectedTab = tab; } } } else { return window.openDialog("chrome://flashvideodownloader/content/send_form.xul",null,'chrome,centerscreen,dependent',window.content.document.location.host); } } catch(e) { //alert("DownloadLink\n" + e); } }, download_from_any_page : function () { try { var mediaNodes = []; var allUrls={}; var nodeByUrl={}; var serviceNeed={}; var embs=window.content.document.getElementsByTagName('embed'); if(embs.length>0) { for(var i=0;i<embs.length;i++) { var emb = embs[i]; var url = null; if(emb.src.match(/\.youtube\./i)) { emb.src.match(/youtube.com\/v\/(.{11})/i); url = 'http://www.youtube.com/watch?v='+RegExp.$1; } else if(emb.src.match(/\.santabanta\./i)) { emb.getAttribute('flashvars').match(/video_id=([\d]+)/i); url = 'http://www.santabanta.com/video.asp?video='+RegExp.$1; } else if(emb.src.match(/\.google\./i)) { emb.src.match(/docid=([\d]+)/i); url = 'http://video.google.com/videoplay?docid='+RegExp.$1; } else if(emb.src.match(/player\.hulu\.com\/embed\/myspace_viral_player/i)) { emb.src.match(/videoID=([\d]+)/i); url = 'http://mediaNodes.myspace.com/index.cfm?fuseaction=mediaNodes.individual&VideoID='+RegExp.$1; } else if(emb.src.match(/\.collegehumor\./i)) { emb.src.match(/clip_id=([\d]+)/i); url = 'http://www.collegehumor.com/video:'+RegExp.$1; } else if(emb.src.match(/\.metacafe\./i)) { emb.src.match(/fplayer\/([\d]+)\/(.*)\.swf/i); url = 'http://www.metacafe.com/watch/'+RegExp.$1+'/'+RegExp.$2+'/'; } else if(emb.src.match(/\.dailymotion\./i)) { emb.src.match(/swf\/([^&]+)/i); url = 'http://www.dailymotion.com/video/'+RegExp.$1; } else if(emb.src.match(/\.dada\.net/i)) { emb.getAttribute('flashvars').match(/mediaID=([\d]+)/i); url = 'http://ru.dada.net/video/'+RegExp.$1+'/'; } else if(emb.src.match(/\.redtube\./i)) { emb.src.match(/\?id=([\d]+)/i); url = 'http://www.redtube.com/'+RegExp.$1; } if (url != null && allUrls[url] == null) { allUrls[url]=""; // prevent duplicates mediaNodes.push(url); nodeByUrl[url] = emb.parentNode; serviceNeed[url] = true; } } } //var mes; //while(mes=mediaNodes.pop())alert(mes); var nodes = []; var rootUrl = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI); rootUrl.spec = window.content.document.URL; var mediaPattern="mpg|mpeg|mp3|mp4|avi|rm|wmv|mov|flv|swf"; //r var mPatt=new RegExp("^.*\\.(?:"+mediaPattern+")$","i"); var dom=window.content.document; var xpr=dom.evaluate(".//a[@href]", dom, null, 5, // == Components.interfaces.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null); var node0=xpr.iterateNext(); while(node0!=null) { var url=node0.getAttribute("href"); if(mPatt.exec(url)!=null) nodes.push(node0); node0=xpr.iterateNext(); } // Searching src xpr=dom.evaluate(".//embed[@src]", dom, null, 5, // == Components.interfaces.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null); node0=xpr.iterateNext(); while(node0!=null) { var url=node0.getAttribute("src"); if(mPatt.exec(url)!=null) nodes.push(node0); node0=xpr.iterateNext(); } for(var i=0;i<nodes.length;i++) { var node=nodes[i]; var url=node.getAttribute("href"); if (url == null) { url=node.getAttribute("src"); if (url != null) node = node.parentNode; } if(allUrls[url]!=null) continue; allUrls[url]=""; if(mPatt.exec(url)==null) continue; //var hrefParts=/^(.*[^0-9])?([0-9]+)([^\/]*?\.[^\/]*?)$/.exec(url); //if(hrefParts!=null && hrefParts.length==4) //{ // var ext = /.*\.(.*?)$/.exec(hrefParts[3])[1]; //} var urlStr=rootUrl.resolve(url); mediaNodes.push(urlStr); nodeByUrl[urlStr] = node; } if(mediaNodes.length>0) { return window.openDialog("chrome://flashvideodownloader/content/pagevids.xul",null,'chrome,centerscreen,dependent,scrollbars=yes', rootUrl.spec, mediaNodes, nodeByUrl, serviceNeed); } } catch(e) { //alert("download_from_any_page\n" + e); } }, tool_icon_menu : function(loc) { var hr=''; if(loc=='h')hr='http://www.flashvideodownloader.org/helpfirefox.php'; if(loc=='c')hr='http://www.flashvideodownloader.org/fvd-suite/'; if(loc=='f')hr='http://www.flashvideodownloader.org/flash-converter/contact/index.php'; window.content.document.location.href=hr; }, show_options : function() { return window.openDialog("chrome://flashvideodownloader/content/options.xul",null,'chrome,centerscreen,toolbar,dependent',false); }, search_video : function() { return window.openDialog("chrome://flashvideodownloader/content/searchvideo.xul",null,'chrome,centerscreen,dependent',false); }, myLoadHandler : function(e) { FlashVD.init(); var hotk; try { var hotk=FlashVD.options.getCharPref('hotkey'); var hotm=FlashVD.options.getCharPref('hot_mod'); }catch(e){return;} window.removeEventListener(e.type, arguments.callee, false); document.getElementById("ila_hotkey").setAttribute("key",hotk); document.getElementById("ila_hotkey").setAttribute("modifiers",hotm); } } // FlashVD window.addEventListener("load", FlashVD.myLoadHandler, false); window.document.addEventListener("load", FlashVD.set_icon, true); window.addEventListener("load", FlashVD.ila_load, false); //window.document.addEventListener("DOMContentLoaded", set_icon, false);